package com.hellpro.lolbox.home.presenter;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.bean.VideoBean;
import com.hellpro.lolbox.bean.ZXSS;
import com.hellpro.lolbox.bean.ZXTT;

import java.util.ArrayList;
import java.util.List;

/**
 * Package_Name: com.hellpro.lolbox.home.presenter
 * Description :
 * author: HellPermanent
 * date:  2016/10/21 13:12
 * remarks：
 */
public class ZXCommListAdapter extends BaseAdapter {
private  List<ZXTT.DataBean> mTList;
    private  List<ZXSS.DataBean>mSList;
    private  List<VideoBean.DataBean> mSPLIst;
    private static  final  int ZXT= 0;
    private static  final  int ZXSP= 1;
    private static  final  int ZXS =2;
 private  int mIndex;
public  ZXCommListAdapter(){
    mTList = new ArrayList<>();
    mSList = new ArrayList<>();
    mSPLIst = new ArrayList<>();
}
    public void setZXData(Object o,int index){

        mIndex = index;
        if (index==ZXT) {
            ZXTT  zxtt = (ZXTT) o;
            mTList.addAll(zxtt.getData());
            notifyDataSetChanged();

        }else if (index==ZXS){
            ZXSS zxss = (ZXSS) o;
            mSList.addAll(zxss.getData());
            notifyDataSetChanged();

        }else  if(index ==ZXSP){
            VideoBean zxsp = (VideoBean) o;
            mSPLIst .addAll(zxsp.getData());
            notifyDataSetChanged();
        }
    }


    @Override
    public int getCount() {
        if (mIndex == ZXT){
            return  mTList==null?0:mTList.size();
        }else if (mIndex==ZXS){
            return  mSList==null?0:mSList.size();}else  if (
                mIndex ==ZXSP
                ){
            return  mSPLIst == null?0:mSPLIst.size();
        }

        return  0;
    }

    @Override
    public Object getItem(int position) {
        if (mIndex == ZXT){
            return  mTList==null?null:mTList.get(position);
        }else if (mIndex==ZXS){
            return  mSList==null?null:mSList.get(position);}
        else if (mIndex ==ZXS){
            return  mSPLIst==null?null:mSPLIst.get(position);
        }
        return  null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder;
        if (convertView==null){
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_listitem, parent, false);
            mHolder = new Holder();
            mHolder.content = (TextView) convertView.findViewById(R.id.common_video_content);
            mHolder.num = (TextView) convertView.findViewById(R.id.common_video_num);
            mHolder.title = (TextView) convertView.findViewById(R.id.common_video_title);
            mHolder.phtoto = (SimpleDraweeView) convertView.findViewById(R.id.common_video_photo);
            mHolder.readplay = (TextView) convertView.findViewById(R.id.common_video_yuedubofang);
            convertView.setTag(mHolder);
        }
        else {
            mHolder = (Holder) convertView.getTag();
        }
        if (mIndex == ZXT){
            ZXTT.DataBean dataBean =  mTList.get(position);
            mHolder.num.setText(dataBean.getReadCount());
            if (dataBean.getType().equals("video")){
                mHolder.readplay.setText("播放");}else {
                mHolder.readplay.setText("阅读");
            }

            mHolder.content.setText(dataBean.getContent());
            String photo = dataBean.getPhoto();
            Uri uri =Uri.parse(photo);
            mHolder.phtoto.setImageURI(uri);
            mHolder.title.setText(dataBean.getTitle());
            return convertView;
        }else if (mIndex==ZXS){
            ZXSS.DataBean dataBean = mSList.get(position);
            mHolder.num.setText(dataBean.getReadCount());
            if (dataBean.getType().equals("video")){
                mHolder.readplay.setText("播放");}else {
                mHolder.readplay.setText("阅读");
            }

            mHolder.content.setText(dataBean.getContent());
            String photo = dataBean.getPhoto();
            Uri uri =Uri.parse(photo);
            mHolder.phtoto.setImageURI(uri);
            mHolder.title.setText(dataBean.getTitle());
            return convertView;
        }else if (mIndex ==ZXSP){
            VideoBean.DataBean dataBean = mSPLIst.get(position);
            mHolder.num.setText(dataBean.getReadCount());
            if (dataBean.getType().equals("video")){
                mHolder.readplay.setText("播放");}else {
                mHolder.readplay.setText("阅读");
            }

            mHolder.content.setText(dataBean.getContent());
            String photo = dataBean.getPhoto();
            Uri uri =Uri.parse(photo);
            mHolder.phtoto.setImageURI(uri);
            mHolder.title.setText(dataBean.getTitle());
            return convertView;
        }


      return  null;
    }


    private static  class Holder{
        SimpleDraweeView phtoto;
        TextView title;
        TextView content;
        TextView readplay;
        TextView num;
    }
}
